<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\module;

use think\Service as BaseService;

class Service extends BaseService
{
    public function boot()
    {
        $this->app->event->listen('AppInit', function () {
            $this->auto();
        });
    }

    public function auto()
    {
        $url_node = explode('/', $_SERVER['REQUEST_URI']);
        $ds = '/';

        $url_node = array_values(array_filter($url_node));
        $url_node[0] = isset($url_node[0]) ? $url_node[0] : 'index';
        $url_node[1] = isset($url_node[1]) ? $url_node[1] : 'index';
        $url_node[2] = isset($url_node[2]) ? $url_node[2] : 'index';
        unset($url_node[0]);

        $ds .= join('/', $url_node);
        $_SERVER['REQUEST_URI'] = $ds;
        $_SERVER['PATH_INFO'] = '/' . join('/', $url_node);
        $_SERVER['QUERY_STRING'] = 's=/' . join('/', $url_node);
        $_POST['s'] = $_GET['s'] = $_REQUEST['s'] = '/' . join('/', $url_node);
    }
}
